/**
 * 
 */
package net.betou.trade.main.manager.impl;

import net.betou.common.hibernate3.Updater;
import net.betou.trade.entity.main.AgentAndAdmins;
import net.betou.trade.entity.main.AgentAndAdminsExt;
import net.betou.trade.main.dao.AgentAndAdminsExtDao;
import net.betou.trade.main.manager.AgentAndAdminsExtMng;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 叶装装
 */
@Service
@Transactional
public class AgentAndAdminsExtMngImpl implements AgentAndAdminsExtMng{

	public AgentAndAdminsExt save( AgentAndAdminsExt ext, AgentAndAdmins bean ) {
		ext.blankToNull( );
		ext.setAdmin( bean );
		dao.save( ext );
		return ext;
	}

	public AgentAndAdminsExt update( AgentAndAdminsExt ext, AgentAndAdmins bean ) {
		AgentAndAdminsExt entity = dao.findById( bean.getId( ) );
		if( entity == null ){
			entity = save( ext, bean );
			bean.getAdminExt( ).add( entity );
			return entity;
		}else{
			Updater< AgentAndAdminsExt > updater = new Updater< AgentAndAdminsExt >( ext );
			updater.include( "gender" );
			updater.include( "birthday" );
			ext = dao.updateByUpdater( updater );
			ext.blankToNull( );
			return ext;
		}
	}

	@Autowired
	private AgentAndAdminsExtDao dao;

}
